home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / lisp / iso / iso-acc.el.z / iso-acc.el
Encoding:
Text File  |  1998-05-21  |  18.7 KB  |  504 lines

  1. ;;; iso-acc.el --- minor mode providing electric accent keys
  2.  
  3. ;; Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc.
  4.  
  5. ;; Author: Johan Vromans
  6. ;; Maintainer: Alexandre Oliva <oliva@dcc.unicamp.br>
  7. ;; Keywords: i18n
  8. ;; $Revision: 1.15 $
  9. ;; $Date: 1997/07/04 22:10:32 $
  10.  
  11. ;; This file is part of GNU Emacs.
  12.  
  13. ;; GNU Emacs is free software; you can redistribute it and/or modify
  14. ;; it under the terms of the GNU General Public License as published by
  15. ;; the Free Software Foundation; either version 2, or (at your option)
  16. ;; any later version.
  17.  
  18. ;; GNU Emacs is distributed in the hope that it will be useful,
  19. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21. ;; GNU General Public License for more details.
  22.  
  23. ;; You should have received a copy of the GNU General Public License
  24. ;; along with GNU Emacs; see the file COPYING.  If not, write to the
  25. ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  26. ;; Boston, MA 02111-1307, USA.
  27.  
  28. ;;; Commentary:
  29.  
  30. ;; Function `iso-accents-mode' activates a minor mode in which
  31. ;; typewriter "dead keys" are emulated.  The purpose of this emulation
  32. ;; is to provide a simple means for inserting accented characters
  33. ;; according to the ISO-8859-1 and other character sets.
  34. ;;
  35. ;; In `iso-accents-mode', pseudo accent characters are used to
  36. ;; introduce accented keys.  The pseudo-accent characters are:
  37. ;;
  38. ;;   '  (minute)    -> grave accent
  39. ;;   `  (backtick)  -> acute accent
  40. ;;   "  (second)    -> diaeresis
  41. ;;   ^  (caret)     -> circumflex
  42. ;;   ~  (tilde)     -> tilde over the character
  43. ;;   /  (slash)     -> slash through the character
  44. ;;                     Also:  /A is A-with-ring and /E is AE ligature.
  45. ;;   .  (dot)       -> dot over the character
  46. ;;   ,  (cedilla)   -> cedilla under the character (some languages only)
  47. ;;
  48. ;; The action taken depends on the key that follows the pseudo accent.
  49. ;; In general: 
  50. ;;
  51. ;;   pseudo-accent + appropriate letter -> accented letter
  52. ;;   pseudo-accent + space -> pseudo-accent (except comma)
  53. ;;   pseudo-accent + pseudo-accent -> accent (if available)
  54. ;;   pseudo-accent + other -> pseudo-accent + other
  55. ;;
  56. ;; If the pseudo-accent is followed by anything else than a 
  57. ;; self-insert-command, the dead-key code is terminated, the
  58. ;; pseudo-accent inserted 'as is' and the bell is rung to signal this.
  59. ;;
  60. ;; Function `iso-accents-mode' can be used to enable the iso accents
  61. ;; minor mode, or disable it.
  62.  
  63. ;; If you want only some of these characters to serve as accents,
  64. ;; add a language to `iso-languages' which specifies the accent characters
  65. ;; that you want, then select the language with `iso-accents-customize'.
  66.  
  67. ;;; Code:
  68.  
  69. (provide 'iso-acc)
  70.  
  71. ;; multiple Emacs versions compatibility section
  72.  
  73. (if (fboundp 'make-char)
  74.     (defun iso-make-char (charset char)
  75.       (cond
  76.        ((integerp char) (make-char charset char))
  77.        ((and (char-or-string-p char) (not (stringp char))) char)
  78.        (t (error "invalid character"))))
  79.   (defun iso-make-char (charset char) "Returns its second argument" char))
  80.  
  81. (if (fboundp 'read-event)
  82.     (defalias 'iso-read-event 'read-event)
  83.   (defun iso-read-event ()
  84.     (event-key (next-command-event))))
  85.  
  86. (if (fboundp 'character-to-event)
  87.     (progn
  88.       (defun iso-char-list-to-event (l)
  89.     "returns an event containing the given list of characters"
  90.     (character-to-event l))
  91.       (defun iso-char-to-event (ch)
  92.     "returns an event containing the given character"
  93.     (iso-char-list-to-event (list ch))))
  94.   (defalias 'iso-char-to-event 'identity)
  95.   (defalias 'iso-char-list-to-event 'identity))
  96.  
  97. (if (fboundp 'this-single-command-keys) ()
  98.   (if (string-match "Lucid" (version))
  99.       (defun this-single-command-keys ()
  100.     (setq this-command (not (this-command-keys)))
  101.     (this-command-keys))
  102.     (defun this-single-command-keys () (this-command-keys))))
  103.  
  104. ;; end of compatibility section
  105.  
  106. (defvar iso-languages
  107.   '(("catalan"
  108.      ;; Note this includes some extra characters used in Spanish,
  109.      ;; on the idea that someone who uses Catalan is likely to use Spanish
  110.      ;; as well.
  111.      (?' (?A . ?\301) (?E . ?\311) (?I . ?\315) (?O . ?\323) (?U . ?\332)
  112.      (?a . ?\341) (?e . ?\351) (?i . ?\355) (?o . ?\363) (?u . ?\372)
  113.      (?\  . ?'))
  114.      (?` (?A . ?\300) (?E . ?\310) (?O . ?\322)
  115.      (?a . ?\340) (?e . ?\350) (?o . ?\362) (?\  . ?`))
  116.      (?\" (?I . ?\317) (?U . ?\334) (?i . ?\357) (?u . ?\374) (?\  . ?\"))
  117.      (?~ (?C . ?\307) (?N . ?\321) (?c . ?\347) (?n . ?\361)
  118.      (?> . ?\273) (?< . ?\253) (?! . ?\241) (?? . ?\277)
  119.      (?\  . ?~)))
  120.  
  121.     ("esperanto"
  122.      (?^ (?H . ?\246) (?J . ?\254) (?h . ?\266) (?j . ?\274) (?C . ?\306)
  123.      (?G . ?\330) (?S . ?\336) (?c . ?\346) (?g . ?\370) (?s . ?\376)
  124.      (?^ . ?^) (?\  . ?^))
  125.      (?~ (?U . ?\335) (?u . ?\375) (?\  . ?~)))
  126.  
  127.     ("french"
  128.      (?' (?E . ?\311) (?C . ?\307)
  129.      (?e . ?\351) (?c . ?\347)
  130.      (?\  . ?') (space . ?'))
  131.      (?` (?A . ?\300) (?E . ?\310) (?U . ?\331)
  132.      (?a . ?\340) (?e . ?\350) (?u . ?\371)
  133.      (?\  . ?`) (space . ?`))
  134.      (?^ (?A . ?\302) (?E . ?\312) (?I . ?\316) (?O . ?\324) (?U . ?\333)
  135.      (?a . ?\342) (?e . ?\352) (?i . ?\356) (?o . ?\364) (?u . ?\373)
  136.      (?\  . ?^) (space . ?^))
  137.      (?\" (?E . ?\313) (?I . ?\317)  
  138.           (?e . ?\353) (?i . ?\357)
  139.       (?\  . ?\") (space . ?\"))
  140.      (?~ (?< . ?\253) (?> . ?\273)
  141.      (?C . ?\307) (?c . ?\347)
  142.      (?\  . ?~) (space . ?~))
  143.      (?, (?c . ?\347) (?C . ?\307) (?, . ?,)))
  144.     
  145.     ("german"
  146.      (?\" (?A . ?\304) (?O . ?\326) (?U . ?\334)
  147.       (?a . ?\344) (?o . ?\366) (?u . ?\374) (?s . ?\337) (?\  . ?\")))
  148.  
  149.     ("irish"
  150.      (?' (?A . ?\301) (?E . ?\311) (?I . ?\315) (?O . ?\323) (?U . ?\332)
  151.      (?a . ?\341) (?e . ?\351) (?i . ?\355) (?o . ?\363) (?u . ?\372)
  152.      (?\  . ?') (space . ?')))
  153.  
  154.     ("portuguese"
  155.      (?' (?A . ?\301) (?E . ?\311) (?I . ?\315) (?O . ?\323) (?U . ?\332)
  156.      (?C . ?\307) (?a . ?\341) (?e . ?\351) (?i . ?\355) (?o . ?\363)
  157.      (?u . ?\372) (?c . ?\347) (?\  . ?') (space . ?'))
  158.      (?` (?A . ?\300) (?a . ?\340) (?\  . ?`) (space . ?`))
  159.      (?^ (?A . ?\302) (?E . ?\312) (?O . ?\324) (?a . ?\342) (?e . ?\352)
  160.      (?o . ?\364) (?\  . ?^) (space . ?^))
  161.      (?\" (?U . ?\334) (?u . ?\374) (?\  . ?\") (space . ?\"))
  162.      (?~ (?A . ?\303) (?O . ?\325)
  163.      (?a . ?\343) (?o . ?\365)
  164.      (?\  . ?~) (space . ?~))
  165.      (?, (?c . ?\347) (?C . ?\307) (?, . ?,)))
  166.  
  167.     ("spanish"
  168.      (?' (?A . ?\301) (?E . ?\311) (?I . ?\315) (?O . ?\323) (?U . ?\332)
  169.      (?a . ?\341) (?e . ?\351) (?i . ?\355) (?o . ?\363) (?u . ?\372)
  170.      (?\  . ?'))
  171.      (?\" (?U . ?\334) (?u . ?\374) (?\  . ?\"))
  172.      (?~ (?N . ?\321) (?n . ?\361) (?> . ?\273) (?< . ?\253) (?! . ?\241)
  173.      (?? . ?\277) (?\  . ?~)))
  174.     
  175.     ("latin-1"
  176.      (?' (?A . ?\301) (?E . ?\311) (?I . ?\315) (?O . ?\323) (?U . ?\332)
  177.      (?Y . ?\335) (?a . ?\341) (?e . ?\351) (?i . ?\355) (?o . ?\363)
  178.      (?u . ?\372) (?y . ?\375) (?' . ?\264) (?\  . ?') (space . ?'))
  179.      (?` (?A . ?\300) (?E . ?\310) (?I . ?\314) (?O . ?\322) (?U . ?\331)
  180.      (?a . ?\340) (?e . ?\350) (?i . ?\354) (?o . ?\362) (?u . ?\371)
  181.      (?` . ?`) (?\  . ?`) (space . ?`))
  182.      (?^ (?A . ?\302) (?E . ?\312) (?I . ?\316) (?O . ?\324) (?U . ?\333)
  183.      (?a . ?\342) (?e . ?\352) (?i . ?\356) (?o . ?\364) (?u . ?\373)
  184.      (?^ . ?^) (?\  . ?^) (space . ?^))
  185.      (?\" (?A . ?\304) (?E . ?\313) (?I . ?\317) (?O . ?\326) (?U . ?\334)
  186.       (?a . ?\344) (?e . ?\353) (?i . ?\357) (?o . ?\366) (?s . ?\337)
  187.       (?u . ?\374) (?y . ?\377) (?\" . ?\250) (?\  . ?\") (space . ?\"))
  188.      (?~ (?A . ?\303) (?C . ?\307) (?D . ?\320) (?N . ?\321) (?O . ?\325)
  189.      (?T . ?\336) (?a . ?\343) (?c . ?\347) (?d . ?\360) (?n . ?\361)
  190.      (?o . ?\365) (?t . ?\376) (?> . ?\273) (?< . ?\253) (?~ . ?\270)
  191.      (?! . ?\241) (?? . ?\277)
  192.      (?\  . ?~) (space . ?~))
  193.      (?/ (?A . ?\305) (?E . ?\306) (?O . ?\330) (?a . ?\345) (?e . ?\346)
  194.      (?o . ?\370) (?/ . ?\260) (?\  . ?/) (space . ?/)))
  195.  
  196.     ("latin-2" latin-iso8859-2
  197.      (?' (?A . ?\301) (?C . ?\306) (?D . ?\320) (?E . ?\311) (?I . ?\315)
  198.      (?L . ?\305) (?N . ?\321) (?O . ?\323) (?R . ?\300) (?S . ?\246)
  199.      (?U . ?\332) (?Y . ?\335) (?Z . ?\254)
  200.      (?a . ?\341) (?c . ?\346) (?d . ?\360) (?e . ?\351) (?i . ?\355)
  201.      (?l . ?\345) (?n . ?\361) (?o . ?\363) (?r . ?\340) (?s . ?\266)
  202.      (?u . ?\372) (?y . ?\375) (?z . ?\274)
  203.      (?' . ?\264) (?\  . ?') (space . ?'))
  204.      (?` (?A . ?\241) (?C . ?\307) (?E . ?\312) (?L . ?\243) (?S . ?\252)
  205.      (?T . ?\336) (?Z . ?\257)
  206.      (?a . ?\261) (?l . ?\263) (?c . ?\347) (?e . ?\352) (?s . ?\272)
  207.      (?t . ?\376) (?z . ?\277)
  208.      (?` . ?\252)
  209.      (?. . ?\377) (?\  . ?`) (space . ?`))
  210.      (?^ (?A . ?\302) (?I . ?\316) (?O . ?\324)
  211.      (?a . ?\342) (?i . ?\356) (?o . ?\364)
  212.      (?^ . ?^)            ; no special code?
  213.      (?\  . ?^) (space . ?^))
  214.      (?\" (?A . ?\304) (?E . ?\313) (?O . ?\326) (?U . ?\334)
  215.       (?a . ?\344) (?e . ?\353) (?o . ?\366) (?s . ?\337) (?u . ?\374)
  216.       (?\" . ?\250)
  217.       (?\  . ?\") (space . ?\"))
  218.      (?~ (?A . ?\303) (?C . ?\310) (?D . ?\317) (?L . ?\245) (?N . ?\322)
  219.      (?O . ?\325) (?R . ?\330) (?S . ?\251) (?T . ?\253) (?U . ?\333)
  220.      (?Z . ?\256)
  221.      (?a . ?\343) (?c . ?\350) (?d . ?\357) (?l . ?\265) (?n . ?\362)
  222.      (?o . ?\365) (?r . ?\370) (?s . ?\271) (?t . ?\273) (?u . ?\373)
  223.      (?z . ?\276)
  224.      (?v . ?\242)            ; v accent
  225.      (?~ . ?\242)            ; v accent
  226.      (?. . ?\270)            ; cedilla accent
  227.      (?\  . ?~) (space . ?~)))
  228.  
  229.     ("latin-3" latin-iso8859-3
  230.      (?' (?A . ?\301) (?E . ?\311) (?I . ?\315) (?O . ?\323) (?U . ?\332)
  231.      (?a . ?\341) (?e . ?\351) (?i . ?\355) (?o . ?\363) (?u . ?\372)
  232.      (?' . ?\264) (?\  . ?') (space . ?'))
  233.      (?` (?A . ?\300) (?E . ?\310) (?I . ?\314) (?O . ?\322) (?U . ?\331)
  234.      (?a . ?\340) (?e . ?\350) (?i . ?\354) (?o . ?\362) (?u . ?\371)
  235.      (?` . ?`) (?\  . ?`) (space . ?`))
  236.      (?^ (?A . ?\302) (?C . ?\306) (?E . ?\312) (?G . ?\330)
  237.      (?H . ?\246) (?I . ?\316) (?J . ?\254) (?O . ?\324)
  238.      (?S . ?\336) (?U . ?\333)
  239.      (?a . ?\342) (?c . ?\346) (?e . ?\352) (?g . ?\370) (?h . ?\266)
  240.      (?i . ?\356) (?j . ?\274) (?o . ?\364) (?s . ?\376) (?u . ?\373)
  241.      (?^ . ?^) (?\  . ?^) (space . \^))
  242.      (?\" (?A . ?\304) (?E . ?\313) (?I . ?\317) (?O . ?\326) (?U . ?\334)
  243.       (?a . ?\344) (?e . ?\353) (?i . ?\357) (?o . ?\366) (?u . ?\374)
  244.       (?s . ?\337)
  245.       (?\" . ?\250) (?\  . ?\") (space . ?\"))
  246.      (?. (?C . ?\305) (?G . ?\325) (?I . ?\251) (?Z . ?\257)
  247.      (?c . ?\345) (?g . ?\365) (?z . ?\277))
  248.      (?~ (?A . ?\303) (?C . ?\307) (?D . ?\320) (?G . ?\253) (?N . ?\321)
  249.      (?O . ?\325) (?S . ?\252) (?U . ?\335)
  250.      (?a . ?\343) (?c . ?\347) (?d . ?\360) (?g . ?\273) (?n . ?\361)
  251.      (?o . ?\365) (?s . ?\252) (?u . ?\375)
  252.      (?h . ?\261) (?$ . ?\245) (?` . ?\242)
  253.      (?~ . ?\270) (?\  . ?~) (space . ?~))
  254.      (?/ (?C . ?\305) (?G . ?\325) (?H . ?\241) (?I . ?\251) (?Z . ?\257) 
  255.      (?c . ?\345) (?g . ?\365) (?h . ?\261) (?i . ?\271) (?z . ?\277)
  256.      (?r . ?\256) (?. . ?\377) (?# . ?\243) (?$ . ?\244)
  257.      (?/ . ?\260) (?\  . ?/) (space . ?/)))
  258.     )
  259.   "List of language-specific customizations for the ISO Accents mode.
  260.  
  261. Each element of the list is of the form
  262.  
  263.     (LANGUAGE [CHARSET]
  264.      (PSEUDO-ACCENT MAPPINGS)
  265.      (PSEUDO-ACCENT MAPPINGS)
  266.      ...)
  267.  
  268. LANGUAGE is a string naming the language.
  269. CHARSET (which may be omitted) is the symbol name
  270.  of the character set used in this language.
  271.  If CHARSET is omitted, latin-iso8859-1 is the default.
  272. PSEUDO-ACCENT is a char specifying an accent key.
  273. MAPPINGS are cons cells of the form (CHAR . ISO-CHAR).
  274.  
  275. The net effect is that the key sequence PSEUDO-ACCENT CHAR is mapped
  276. to ISO-CHAR on input.")
  277.  
  278. (defvar iso-language nil
  279.   "Language for which ISO Accents mode is currently customized.
  280. Change it with the `iso-accents-customize' function.")
  281.  
  282. (defvar iso-accents-list nil
  283.   "Association list for ISO accent combinations, for the chosen language.")
  284.  
  285. (defvar iso-accents-charset 'latin-iso8859-1
  286.   "Charset that will be used for generated characters.")
  287.  
  288. (defvar iso-accents-mode nil
  289.   "*Non-nil enables ISO Accents mode.
  290. Setting this variable makes it local to the current buffer.
  291. See the function `iso-accents-mode'.")
  292. (make-variable-buffer-local 'iso-accents-mode)
  293.  
  294. (defvar iso-accents-enable '(?' ?` ?^ ?\" ?~ ?/ ?, ?.)
  295.   "*List of accent keys that become prefixes in ISO Accents mode.
  296. The default is (?' ?` ?^ ?\" ?~ ?/ ?, ?.), which contains all the supported
  297. accent keys.  If you set this variable to a list in which some of those
  298. characters are missing, the missing ones do not act as accents.
  299.  
  300. Note that if you specify a language with `iso-accents-customize',
  301. that can also turn off certain prefixes (whichever ones are not needed in
  302. the language you choose).")
  303.  
  304. (defun iso-accents-accent-key (prompt)
  305.   "Modify the following character by adding an accent to it."
  306.   ;; Pick up the accent character.
  307.   (if (and iso-accents-mode
  308.        (memq last-input-char iso-accents-enable))
  309.       (iso-accents-compose prompt)
  310.     (char-to-string last-input-char)))
  311.  
  312. (defun iso-accents-compose (prompt)
  313.   (let* ((first-char last-input-char)
  314.      (list (assq first-char iso-accents-list))
  315.      (charset iso-accents-charset)
  316.      ;; Wait for the second key and look up the combination.
  317.      (second-char (if (or prompt
  318.                   (not (eq (key-binding "a")
  319.                        'self-insert-command))
  320.                   ;; Not at start of a key sequence.
  321.                   (> (length (this-single-command-keys)) 1)
  322.                   ;; Called from anything but the command loop.
  323.                   this-command)
  324.               (progn
  325.                 (message "%s%c"
  326.                      (or prompt "Compose with ")
  327.                      first-char)
  328.                 (iso-read-event))
  329.             (insert first-char)
  330.             (prog1 (iso-read-event)
  331.               (delete-region (1- (point)) (point)))))
  332.      (entry (cdr (assq second-char list))))
  333.     (if entry
  334.     (progn
  335.       (if (and (consp entry) (symbolp (car entry)))
  336.           (setq charset (car entry)
  337.             entry (cdr entry)))
  338.     ;; Found it: return the mapped char
  339.       (vector
  340.        (iso-char-to-event (iso-make-char charset entry))))
  341.       ;; Otherwise, advance and schedule the second key for execution.
  342.       (setq unread-command-events (cons (iso-char-list-to-event
  343.                      (list second-char))
  344.                     unread-command-events))
  345.       (vector (iso-char-to-event first-char)))))
  346.  
  347. ;; It is a matter of taste if you want the minor mode indicated
  348. ;; in the mode line...
  349. ;; If so, uncomment the next four lines.
  350. ;; (or (assq 'iso-accents-mode minor-mode-alist)
  351. ;;     (setq minor-mode-alist
  352. ;;           (append minor-mode-alist
  353. ;;                   '((iso-accents-mode " ISO-Acc")))))
  354.  
  355. ;;;###autoload
  356. (defun iso-accents-mode (&optional arg)
  357.   "Toggle ISO Accents mode, in which accents modify the following letter.
  358. This permits easy insertion of accented characters according to ISO-8859-1.
  359. When Iso-accents mode is enabled, accent character keys
  360. \(`, ', \", ^, / and ~) do not self-insert; instead, they modify the following
  361. letter key so that it inserts an ISO accented letter.
  362.  
  363. You can customize ISO Accents mode to a particular language
  364. with the command `iso-accents-customize'.
  365.  
  366. Special combinations: ~c gives a c with cedilla,
  367. ~d gives an Icelandic eth (d with dash).
  368. ~t gives an Icelandic thorn.
  369. \"s gives German sharp s.
  370. /a gives a with ring.
  371. /e gives an a-e ligature.
  372. ~< and ~> give guillemots.
  373. ~! gives an inverted exclamation mark.
  374. ~? gives an inverted question mark.
  375.  
  376. With an argument, a positive argument enables ISO Accents mode, 
  377. and a negative argument disables it."
  378.  
  379.   (interactive "P")
  380.  
  381.   (if (if arg
  382.       ;; Negative arg means switch it off.
  383.       (<= (prefix-numeric-value arg) 0)
  384.     ;; No arg means toggle.
  385.     iso-accents-mode)
  386.       (setq iso-accents-mode nil)
  387.  
  388.     ;; Enable electric accents.
  389.     (setq iso-accents-mode t)))
  390.  
  391. (defun iso-accents-customize (language)
  392.   "Customize the ISO accents machinery for a particular language.
  393. It selects the customization based on the specifications in the
  394. `iso-languages' variable."
  395.   (interactive (list (completing-read "Language: " iso-languages nil t)))
  396.   (let ((table (cdr (assoc language iso-languages)))
  397.     tail)
  398.     (if (not table)
  399.     (error "Unknown language `%s'" language)
  400.       (setq iso-accents-charset (if (symbolp (car table))
  401.                     (car table)
  402.                   'latin-iso8859-1))
  403.       (if (symbolp (car table))
  404.       (setq table (cdr table)))
  405.       (setq iso-language language
  406.         iso-accents-list table)
  407.       (if key-translation-map
  408.       (substitute-key-definition
  409.        'iso-accents-accent-key nil key-translation-map)
  410.     (setq key-translation-map (make-sparse-keymap)))
  411.       ;; Set up translations for all the characters that are used as
  412.       ;; accent prefixes in this language.
  413.       (setq tail iso-accents-list)
  414.       (while tail
  415.     (define-key key-translation-map (vector (iso-char-to-event
  416.                          (car (car tail))))
  417.       'iso-accents-accent-key)
  418.     (setq tail (cdr tail))))))
  419.  
  420. (defun iso-accentuate (start end)
  421.   "Convert two-character sequences in region into accented characters.
  422. Noninteractively, this operates on text from START to END.
  423. This uses the same conversion that ISO Accents mode uses for type-in."
  424.   (interactive "r")
  425.   (save-excursion
  426.     (save-restriction
  427.       (narrow-to-region start end)
  428.       (goto-char start)
  429.       (forward-char 1)
  430.       (let (entry)
  431.     (while (< (point) end)
  432.       (if (and (memq (preceding-char) iso-accents-enable)
  433.            (setq entry (cdr (assq (following-char) (assq (preceding-char) iso-accents-list)))))
  434.           (progn
  435.         (forward-char -1)
  436.         (delete-char 2)
  437.         (insert entry)
  438.         (setq end (1- end)))
  439.         (forward-char 1)))))))
  440.  
  441. (defun iso-accent-rassoc-unit (value alist)
  442.   (let (elt acc)
  443.     (while (and alist (not elt))
  444.       (setq acc (car (car alist))
  445.         elt (car (rassq value (cdr (car alist))))
  446.         alist (cdr alist)))
  447.     (if elt
  448.     (cons acc elt))))
  449.  
  450. (defun iso-unaccentuate (start end)
  451.   "Convert accented characters in the region into two-character sequences.
  452. Noninteractively, this operates on text from START to END.
  453. This uses the opposite of the conversion done by ISO Accents mode for type-in."
  454.   (interactive "r")
  455.   (save-excursion
  456.     (save-restriction
  457.       (narrow-to-region start end)
  458.       (goto-char start)
  459.       (let (entry)
  460.     (while (< (point) end)
  461.       (if (and (> (following-char) 127)
  462.            (setq entry (iso-accent-rassoc-unit (following-char)
  463.                                iso-accents-list)))
  464.           (progn
  465.         (delete-char 1)
  466.         (insert (car entry) (cdr entry))
  467.         (setq end (1+ end)))
  468.         (forward-char 1)))))))
  469.  
  470. (defun iso-deaccentuate (start end)
  471.   "Convert accented characters in the region into unaccented characters.
  472. Noninteractively, this operates on text from START to END."
  473.   (interactive "r")
  474.   (save-excursion
  475.     (save-restriction
  476.       (narrow-to-region start end)
  477.       (goto-char start)
  478.       (let (entry)
  479.     (while (< (point) end)
  480.       (if (and (> (following-char) 127)
  481.            (setq entry (iso-accent-rassoc-unit (following-char)
  482.                                iso-accents-list)))
  483.           (progn
  484.         (delete-char 1)
  485.         (insert (cdr entry)))
  486.         (forward-char 1)))))))
  487.  
  488. ;; Set up the default settings.
  489. (iso-accents-customize "latin-1")
  490.  
  491. ;; Use Iso-Accents mode in the minibuffer
  492. ;; if it was in use in the previous buffer.
  493. (defun iso-acc-minibuf-setup ()
  494.   (setq iso-accents-mode
  495.     (save-excursion
  496.       (set-buffer (window-buffer minibuffer-scroll-window))
  497.       iso-accents-mode)))
  498.  
  499. (if (boundp 'minibuffer-setup-hook)
  500.     (add-hook 'minibuffer-setup-hook 'iso-acc-minibuf-setup)
  501.   (add-hook 'minibuf-setup-hook 'iso-acc-minibuf-setup))
  502.  
  503. ;;; iso-acc.el ends here
  504.